package com.zhou.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.zhou.constant.MessageConstant;
import com.zhou.constant.RedisConstant;
import com.zhou.dao.MemberUploadDao;
import com.zhou.entity.PageResult;
import com.zhou.entity.Result;
import com.zhou.pojo.CheckItem;
import com.zhou.pojo.MemberFileReport;
import com.zhou.service.MemberUploadService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import redis.clients.jedis.JedisPool;

@Service(interfaceClass = MemberUploadService.class)
@Transactional
public class MemberUploadServiceImpl implements MemberUploadService {
    @Autowired
    MemberUploadDao memberUploadDao;
    @Override
    public PageResult findByPage(Integer currentPage, Integer pageSize, String queryString) {
        PageHelper.startPage(currentPage,pageSize);
        Page<CheckItem> page = memberUploadDao.findByPage(queryString);
        PageResult pageResult = new PageResult(page.getTotal(), page.getResult());
        return pageResult;
    }

    @Override
    public MemberFileReport findById(Integer id) {
        return memberUploadDao.findById(id);
    }

    @Override
    public void delete(Integer id) {
        memberUploadDao.delete(id);
    }
    @Override
    public Result uploadFileReport(MemberFileReport memberFileReport) {
        if ("1".equals(memberFileReport.getFilestatus())) {
            return new Result(false, MessageConstant.ERROR_UPLOAD);
        }
        memberFileReport.setFilestatus("1");
        memberUploadDao.uploadFileReport(memberFileReport);

        //将文件名称保存到Redis集合中
        String fileName = memberFileReport.getFileurl();
        return new Result(true, MessageConstant.ADD_MEMBERFILEREPORT_SUCCESS);
    }

}
